#include "titlebar.h"
#include "mainwindow.h"
#include <QMouseEvent>
#define VALUE_DIS 5
Titlebar::Titlebar(QWidget *parent) :
    QWidget(parent)
{
    m_bLeftButtonPress = false;
    m_bLeftButtonMove = false;
    //this->setCursor(Qt::ArrowCursor);
}

Titlebar::~Titlebar()
{

}

//鼠标移动事件
void Titlebar::mouseMoveEvent(QMouseEvent *event)
{
    if(m_bLeftButtonPress)
    {
        m_ptMove = event->globalPos();
        emit signal_push_move_event(m_ptMove,m_ptPress);
        //重新设置m_ptPress;
        m_ptPress = m_ptMove;
        m_bLeftButtonMove = true;
    }
    event->ignore();
}

//按下事件
void Titlebar::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        if(m_bLeftButtonMove)
            this->setCursor(Qt::ClosedHandCursor);
        if(event->y()<VALUE_DIS||event->x()<VALUE_DIS||rect().width()-event->x()<5)
        {
            event->ignore();
            return;
        }
        m_ptPress = event->globalPos();
        m_bLeftButtonPress = true;
    }
    event->ignore();
}

//鼠标释放事件
void Titlebar::mouseReleaseEvent(QMouseEvent *event)
{
    //    m_Drag=false;
    if (event->button() == Qt::LeftButton)
    {
        m_bLeftButtonPress = false;
        this->setCursor(Qt::ArrowCursor);
    }
    event->ignore();
}
